//
//  ByViewServiceForInHospitalPrehandMoney.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/12/11.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewServiceForInHospitalPrehandMoney.h"

@implementation ByViewServiceForInHospitalPrehandMoney
{
    UILabel *_titleLabel;
    UIImageView *_explainView;
    UIButton *_agreeButton;
    UILabel *_agreeLabel;
}

- (instancetype)init {
    
    if (self = [super init]) {
        
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.text = @"预交金说明：";
    _titleLabel.font = FONT(16);
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    _titleLabel.textColor = [UIColor blackColor];
    [self addSubview:_titleLabel];
    
    _explainView = [UIImageView new];
    _explainView.image = [UIImage imageWithColor:[UIColor orangeColor]];
    [self addSubview:_explainView];
    
    _agreeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_agreeButton setImage:[UIImage imageNamed:@"购物车未选中"] forState:UIControlStateNormal];
    [_agreeButton setImage:[UIImage imageNamed:@"购物车选中"] forState:UIControlStateSelected];
    [_agreeButton addTarget:self action:@selector(agree:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_agreeButton];
    
    _agreeLabel = [[UILabel alloc] init];
    _agreeLabel.text = @"我同意以上说明";
    _agreeLabel.font = FONT(14);
    _agreeLabel.textAlignment = NSTextAlignmentLeft;
    _agreeLabel.textColor = [UIColor grayColor];
    [self addSubview:_agreeLabel];
    
    
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(@10);
    }];
    [_explainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.mas_bottom).offset(10);
        make.left.equalTo(@10);
        make.right.equalTo(@-10);
        make.height.equalTo(_explainView.mas_width).multipliedBy(0.7);
    }];
    [_agreeButton setImageEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
    [_agreeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_explainView.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.left.equalTo(@0);
        
        make.bottom.equalTo(self);
    }];
    [_agreeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_agreeButton.mas_right);
        make.centerY.equalTo(_agreeButton);
    }];
}

- (void)agree:(UIButton *)button {
    
    button.selected = !button.selected;
}
- (BOOL)agree {
    return _agreeButton.selected;
}

@end
